<template>
    <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <el-form-item label="茶叶商品" prop="good">
        <el-input type="text" v-model="ruleForm.good" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="购买者id" prop="purchaserid">
        <el-input type="number" v-model="ruleForm.purchaserid" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="订单明细" prop="info">
        <el-input type="text" v-model="ruleForm.info" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
</el-form>
</template>
<script>
import {addGoods} from '@/api'
  export default {
    data() {
      return {
        ruleForm: {
          good:'',
          purchaserid: 0,
          info: '',
        },
    }},
    methods: {
      submitForm(formName) {
          let _this = this;
        this.$refs[formName].validate((valid) => {
          if (valid) {
            addGoods(_this.ruleForm).then((res) => {
                if(res){
                    _this.$alert('订单添加成功！', '添加数据', {
                        confirmButtonText: '确定',
                        callback: action => {
                            //跳转
                            _this.$router.push('/goodslist')
                        }
                    });
                }
            })
          } else {
            this.$message.error('请补充信息！');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>